﻿using System;
using System.Reflection;
using System.Windows.Forms;

namespace FilesBackup;

static class Program
{
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    static void Main()
    {
        AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
        Application.EnableVisualStyles();
        // Application.SetHighDpiMode(HighDpiMode.SystemAware);
        Application.SetCompatibleTextRenderingDefault(false);
        var form = new FilesBackupForm();
        Application.Run(form);
    }

    // https://www.cnblogs.com/a849788087/p/6552977.html
    // 引用的dll修改成->不复制
    // 资源的dll修改成->嵌入的资源
    // 入口点写 AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

    /// <summary>
    /// 为了exe不带dll,所以反射自身的资源(资源dll不要用文件夹)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <returns></returns>
    private static Assembly? CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs e)
    {
        var ass = Assembly.GetExecutingAssembly();
        foreach (var name in ass.GetManifestResourceNames())
        {
            var stream = ass.GetManifestResourceStream(name);
            if (stream == null)
                continue;
            var assemblyData = new byte[stream.Length];
            stream.Read(assemblyData, 0, assemblyData.Length);
            return Assembly.Load(assemblyData);
        }
        return null;
    }
}